package com.kudian.restful.controller;

import com.kudian.restful.service.AdService;
import com.kudian.restful.service.LoginSessionService;
import com.kudian.restful.service.RegionService;
import com.kudian.restful.vo.ad.CarouselRetVO;
import com.kudian.restful.vo.ad.MidAdRetVO;
import com.kudian.restful.vo.ad.MidAdVO;
import com.kudian.restful.vo.goods.AddGoodsRetVO;
import com.kudian.restful.vo.region.QueryRegionRetVO;
import com.kudian.restful.vo.region.QueryRegionVO;
import com.kudian.restful.vo.region.RegionItemVO;
import com.kudian.restful.vo.welinfo.WelInfoPageRetVO;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2016/4/27.
 */
@RestController
@RequestMapping("region")
public class RegionController {

    private static final Logger logger = Logger.getLogger(RegionController.class);

    @Autowired
    private RegionService regionService;

    @RequestMapping(value = "queryRegions", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "返回城市", httpMethod = "POST", notes = "返回城市", response = QueryRegionRetVO.class)
    public @ResponseBody QueryRegionRetVO queryRegions(@RequestBody QueryRegionVO vo) {
        QueryRegionRetVO o = new QueryRegionRetVO();
        try {
            // 初始时填写 1
            o.setItems(regionService.queryRegions(vo.getParentId()));
            // 成功
            o.setErrcode(0);
            o.setErrmsg("返回城市信息成功!");
        } catch (Exception e) {
            // 失败
            o.setErrcode(9999);
            o.setErrmsg("返回城市信息失败!");
            e.printStackTrace();
            logger.error(e);
        }
        return o;
    }
}
